package com.ruoyi.common.utils;

import com.ruoyi.common.utils.CL253Api.MessageApi;
import com.ruoyi.common.utils.CL253Api.VoiceApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @Author: wwy
 * @Date: 2021/3/4 11:46
 */
public class CLUtils {
    private static final Logger LOGGER = LoggerFactory.getLogger(CLUtils.class);
    private static String ACCOUNT;
    private static String PASSWORD;
    private static String SEND_MESSAGE_URL;

    private static MessageApi messageApi = null;

    private static String APP_ID;
    private static String APP_KEY;
    private static String SEND_VOICE_URL;

    private static VoiceApi voiceApi = null;



    static {
        Properties properties = new Properties();
        // 使用ClassLoader加载properties配置文件生成对应的输入流
        InputStream in = AipBaiDuUtils.class.getClassLoader().getResourceAsStream("cl253.properties");
        // 使用properties对象加载输入流
        try {
            properties.load(in);
            ACCOUNT = String.valueOf(properties.get("ACCOUNT"));
            PASSWORD = String.valueOf(properties.get("PASSWORD"));
            SEND_MESSAGE_URL = String.valueOf(properties.get("SEND_MESSAGE_URL"));
            APP_ID = String.valueOf(properties.get("APP_ID"));
            APP_KEY = String.valueOf(properties.get("APP_KEY"));
            SEND_VOICE_URL = String.valueOf(properties.get("SEND_VOICE_URL"));
            LOGGER.info("253初始化成功,ACCOUNT:{},PASSWORD:{},SEND_MESSAGE_URL:{},APP_ID:{},API_KEY:{},SEND_VOICE_URL{},",ACCOUNT,PASSWORD,SEND_MESSAGE_URL,APP_ID,APP_KEY,SEND_VOICE_URL);
        } catch (IOException e) {
            LOGGER.info("253初始化失败");
        }
    }

    /**
     * 获取messageApi
     * @return
     */
    public static MessageApi getMessageApi(){
        if(messageApi == null){
            messageApi = new MessageApi(ACCOUNT,PASSWORD,SEND_MESSAGE_URL);
        }
        return messageApi;
    }

    /**
     * 获取voiceApi
     * @return
     */
    public static VoiceApi getVoiceApi(){
        if(voiceApi == null){
            voiceApi = new VoiceApi(APP_ID,APP_KEY,SEND_VOICE_URL);
        }
        return voiceApi;
    }





}
